<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>相册分类</title>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
    <%@include file="../include/commonFile.jsp" %>
</head>
<body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">

                    <form class="layui-form" action="${ctx}/photo/album/list.do" id="myForm" method="post">
                        <input type="hidden" name="pageNo" id="pageNo"/>
                        <input type="hidden" name="photosId" value="${photosTag.photosId}"/>
                        <div class="f-search-bar">
                            <div class="search-container">
                                <ul class="search-form-content">
                                    <li class="form-item-inline">
                                        <label class="search-form-lable">分类名称</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="name" autocomplete="off" class="layui-input"
                                                   value="${photosTag.name}" placeholder="请输入分类名称">
                                        </div>
                                    </li>
                                    <li class="form-item-inline">
                                        <div class="sub-btns" style="width: 262px; text-align: right;">
                                            <a class="layui-btn layui-btn-danger"
                                               href="javascript:submitFunction('#myForm')">查询</a>
                                            <a class="layui-btn layui-btn-normal"
                                               href="javascript:resetFunction('#myForm')">重置</a>
                                        </div>
                                    </li>
                                </ul>
                                <ul class="search-form-content">
                                    <li class="form-item"><label class="search-form-lable">创建时间</label>
                                        <div class="check-btn-inner" id="timeType">
                                            <a id="all" href="javascript:void(0);"
                                               onclick="setTimeType($(this),0,'#myForm')" ${empty input.timeType || input.timeType == 0 ? 'class="active"' : ''}>全部</a>
                                            <a href="javascript:void(0);"
                                               onclick="setTimeType($(this),1,'#myForm')" ${input.timeType == 1 ? 'class="active"' : ''}>今天</a>
                                            <a href="javascript:void(0);"
                                               onclick="setTimeType($(this),2,'#myForm')" ${input.timeType == 2 ? 'class="active"' : ''}>本周内</a>
                                            <a href="javascript:void(0);"
                                               onclick="setTimeType($(this),3,'#myForm')" ${input.timeType == 3 ? 'class="active"' : ''}>本月内</a>
                                            <input type="hidden" name="timeType" value="${input.timeType}"/>
                                        </div>
                                        <div class="layui-inline">
                                            <div class="layui-input-inline">
                                                <input class="layui-input" type="text" name="createStart" value="${empty input.createStart ? '' : fn:substring(input.createStart, 0, 10)}" placeholder="开始日">
                                            </div>
                                            -
                                            <div class="layui-input-inline">
                                                <input class="layui-input" type="text" name="createEnd" value="${empty input.createEnd ? '' : fn:substring(input.createEnd, 0, 10)}" placeholder="截止日">
                                            </div>
                                        </div>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </form>
                    <div class="buttons mt20" style="text-align: right">
                        <a class="layui-btn layui-btn-primary" href="javascript:addAlbum('', '${photosTag.photosId}');">创建分类</a>
                        <a class="layui-btn layui-btn-danger" href="javascript:uploadPic('', '${photosTag.photosId}')">上传照片</a>
                    </div>
                    <div class="my-act-list-content">
                        <ul id="view">
                            <table class="layui-table">
                                <colgroup>
                                    <col width="25%">
                                    <col width="25%">
                                    <col width="25%">
                                    <col>
                                </colgroup>
                                <thead>
                                <tr>
                                    <th>分类名称</th>
                                    <th>照片数量</th>
                                    <th>修改时间</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <c:forEach var="album" items="${list}">
                                    <tr>
                                        <td>${album.name}</td>
                                        <td>${album.imgNum}</td>
                                        <td>
                                            <fmt:formatDate value="${album.updateDate}" pattern="yyyy-MM-dd HH:mm" />
                                        </td>
                                        <td>
                                            <div class="opts-btns tb-opts">
                                                <div class="comm-opts">
                                                    <c:if test="${album.name != '热门' && album.name != '精选'}">
                                                        <a href="javascript:uploadPic('${album.id}', '${album.photosId}')">
                                                            上传照片
                                                        </a>
                                                    </c:if>
                                                    <a href="${ctx}/photo/imgInfo/list.do?albumId=${album.id}" target="_self">
                                                        照片管理
                                                    </a>
                                                    <c:if test="${album.type == 1}">
                                                        <a href="javascript:addAlbum('${album.id}', '${album.photosId}');">
                                                            编辑
                                                        </a>
                                                        <a href="javascript:void(0)" onclick="deleteAlbum('${album.id}', '${album.imgNum}')">
                                                            删除
                                                        </a>
                                                    </c:if>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                </c:forEach>
                                </tbody>
                            </table>
                        </ul>
                    </div>
                    <div id="page_content" class="page-container"></div>
        </div><!--底部-->
        <%@include file="../include/footer.jsp" %>
    </section>
</div>

<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript" src="${ctx}/script/common/table_option.js"></script>
<script type="text/javascript">


    $(function () {
        //加载分页
        loadPageNew({
            elem: 'page_content',
            totalCount: '${page.totalCount}',
            limit: '${page.limit}',
            page: '${page.page}'
        });
        layui.use(['laydate'], function () {
            var laydate = layui.laydate;
            // 查询发布日期
            var start = {
                elem: 'input[name=createStart]'
            };

            var end = {
                elem: 'input[name=createEnd]'
            };
            laydate.render(start);
            laydate.render(end);
        });

    });

    function addAlbum(albumId, photosId) {
        var str;
        if (albumId) {
            str = '编辑';
        } else {
            str = '创建';
        }
        openDialog(str + '分类', '${ctx}/photo/album/addAlbum.do?id=' + albumId + '&photosId=' + photosId, '436px', '239px');
    }

    function openDialog(title, url, width, height, cb, target) {
        var index = layer.open({
            type: 2,
            area: [width, height],
            title: title,
            maxmin: true, //开启最大化最小化按钮
            content: url,
            btn: ['确定', '关闭'],
            yes: function (index, layero) {
                var body = layer.getChildFrame('body', index);
                var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                var inputForm = body.find('#inputForm');
                var top_iframe;
                if (target) {
                    top_iframe = target;//如果指定了iframe，则在改frame中跳转
                } else {
                    top_iframe = '_parent';//获取当前active的tab的iframe
                }
                inputForm.attr("target", top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示

                if (iframeWin.contentWindow.doSubmit()) {
                    setTimeout(function () {
                        top.layer.close(index);
                    }, 100);//延时0.1秒，对应360 7.1版本bug

                    setTimeout(function () {
                        window.location.reload();
                    }, 200);
                }
            },
            cancel: function (index) {
            },
            success: function () {
                $(':focus').blur();
            }
        });
    }

    function deleteAlbum(id, imgNum) {
        var url = '${ctx}/photo/album/delete.do?id='+id;
        var str;
        if (imgNum) {
            imgNum = parseInt(imgNum);
        } else {
            imgNum = 0;
        }
        if (imgNum > 0) {
            str = '相册中有' + imgNum + '张照片';
        } else {
            str = '';
        }
        txz.deleteObject("确认要删除该相册吗？" + str, url)
    }

    function uploadPic(albumId, photosId) {
        txz.openPhotoUpload({
            tagId: albumId,
            id: photosId
        })
    }
</script>
<script type="text/javascript">
    txz.initHeader({
        nav:[{
            name: '活动相册管理',
            href: '${ctx}/photo/photoproject/list.do'
        },{
            name: '${photoProject.name}',
            curr: true
        },{
            name: '相册分类',
            curr: true
        }],
        btns:[{
            name: '返回',
            icon: 'back',
            href: "${ctx}/photo/photoproject/list.do" ,
        }],
        info:'<span class="f12">共<b id="totalCount">${page.totalCount}</b>条记录</span>'
    });
</script>
</body>
</html>